// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Aggregations;

public sealed partial class RandomSamplerAggregation
{
	/// <summary>
	/// <para>
	/// The probability that a document will be included in the aggregated data.
	/// Must be greater than 0, less than 0.5, or exactly 1.
	/// The lower the probability, the fewer documents are matched.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("probability")]
	public double Probability { get; set; }

	/// <summary>
	/// <para>
	/// The seed to generate the random sampling of documents.
	/// When a seed is provided, the random subset of documents is the same between calls.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("seed")]
	public int? Seed { get; set; }

	/// <summary>
	/// <para>
	/// When combined with seed, setting shard_seed ensures 100% consistent sampling over shards where data is exactly the same.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("shard_seed")]
	public int? ShardSeed { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Aggregations.Aggregation(RandomSamplerAggregation randomSamplerAggregation) => Elastic.Clients.Elasticsearch.Aggregations.Aggregation.RandomSampler(randomSamplerAggregation);
}

public sealed partial class RandomSamplerAggregationDescriptor : SerializableDescriptor<RandomSamplerAggregationDescriptor>
{
	internal RandomSamplerAggregationDescriptor(Action<RandomSamplerAggregationDescriptor> configure) => configure.Invoke(this);

	public RandomSamplerAggregationDescriptor() : base()
	{
	}

	private double ProbabilityValue { get; set; }
	private int? SeedValue { get; set; }
	private int? ShardSeedValue { get; set; }

	/// <summary>
	/// <para>
	/// The probability that a document will be included in the aggregated data.
	/// Must be greater than 0, less than 0.5, or exactly 1.
	/// The lower the probability, the fewer documents are matched.
	/// </para>
	/// </summary>
	public RandomSamplerAggregationDescriptor Probability(double probability)
	{
		ProbabilityValue = probability;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The seed to generate the random sampling of documents.
	/// When a seed is provided, the random subset of documents is the same between calls.
	/// </para>
	/// </summary>
	public RandomSamplerAggregationDescriptor Seed(int? seed)
	{
		SeedValue = seed;
		return Self;
	}

	/// <summary>
	/// <para>
	/// When combined with seed, setting shard_seed ensures 100% consistent sampling over shards where data is exactly the same.
	/// </para>
	/// </summary>
	public RandomSamplerAggregationDescriptor ShardSeed(int? shardSeed)
	{
		ShardSeedValue = shardSeed;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		writer.WritePropertyName("probability");
		writer.WriteNumberValue(ProbabilityValue);
		if (SeedValue.HasValue)
		{
			writer.WritePropertyName("seed");
			writer.WriteNumberValue(SeedValue.Value);
		}

		if (ShardSeedValue.HasValue)
		{
			writer.WritePropertyName("shard_seed");
			writer.WriteNumberValue(ShardSeedValue.Value);
		}

		writer.WriteEndObject();
	}
}